<div class="page-group">
    <div class="page" data-page="book_kind">
        <header class="bar bar-nav">
            <a onclick="goback()" class="icon" style="width: 40%">
                <img src="__PUBLIC__/img/iconfont_back@2x.png" class="back_img">
            </a>
        </header>
        <div class="content doublecontent">
            <div class="act_new_top">
                <div><img src="{$d.a_logo}" style="width: 100%;height: 130px;padding: 10px"></div>
                <div class="death_time"><font color="#CCCCCC">活动名称：</font>{$d.title}</div>
                <div class="death_time"><font color="#CCCCCC">报名时间：</font>{:date("Y-m-d",strtotime($d['apply_start']))}至{:date("Y-m-d",strtotime($d['apply_end']))}</div>
                <div class="report_num color_book_kind_titile">可报名{$d.apply_num}人</div>
                <div class="report_num color_book_kind_titile">
                    <s>原价:{$d['price_apply']|number_format=###,2}(报名费)</s><br>
                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s>{$d['price_material']|number_format=###,2}(报名材料费)</s><br>
                       &nbsp;&nbsp;&nbsp;&nbsp;总:<s>{$d['price_apply']+$d['price_material']|number_format=###,2}元</s>
                    <br>会员价:{$d['price_apply_discount']|number_format=###,2}(折后报名费)<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$d['price_material']|number_format=###,2}(报名材料费)<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;总:{$d.price_total|number_format=###,2}元
                </div>
                <div class="report_num color_book_kind_titile">消耗{$d.num_deduct_use}个{$Think.config.act_freenum_name}</div>
            </div>
            <div style="background: #FFF;margin:10px 0px;"  onclick="window.location.href='{:U("User/address")}'">
                <div class="contact_person word_no_wrap">
                    <div class="contact_people">联系人：{$add.name}</div>
                    <div class="contact_num">联系号码：{$add.phone}</div>
                </div>
                <img src="__PUBLIC__/img/xinfen@2x.png" style="width: 100%">
            </div>
            <div class="trans_fee">
                <span style="visibility: hidden">lalala</span>
                <span class="user_info_public">共1个活动  合计：<font class="color_book_kind_titile">￥{$d.price_total|number_format=###,2}</font></span>
            </div>
        </div>
        <nav class="bar bar-tab old_bar">
            <a class="tab-item external" href="#">
                <font color="#000">合计（运费）</font><font class="color_book_kind_titile">￥{$d.price_total|number_format=###,2}</font>
            </a>
            <a class="tab-item external" href="#">
                <input class="save_address" type="button" value="确认" onclick="bear_activity({$d['activity_id']})">
            </a>
        </nav>
    </div>
</div>
<script>
    //生成订单
    function bear_activity($id){
        //防止重复点击
        $(this).attr("onclick", "");
        $.post("{:U('Order/bear_order_activity')}",{id:$id},function(data){
            data = $.parseJSON(data);
            if(data['state']==300){
                // 无活动费用
                $.post("{:U('Pay/fulfill_activity')}",{pay_id:data['pay_id']},function(){
                    window.location.href="{:U('User/activity_join')}";
                });
            }else{
                Unifiedorder(data['pay_id']);
            }
        });
    }
    //统一下单
    function Unifiedorder($pay_id){
        $.post("{:U('Order/getJsApiParameters_activity')}",{id:$pay_id},function(data){
            var data= eval('(' + data + ')');
            if(data.status=="error"){
                alert("无法支付，"+data.message);
            }
            if(data.status=="success"){
                //支付
                callpay(data.message);
            }
        });
    }

    //微信支付
    function callpay(data)
    {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall(data);
        }
    }

    function jsApiCall($jsApiParameters)
    {
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                eval('(' + $jsApiParameters + ')'),
                function(res){
                    WeixinJSBridge.log(res.err_msg);
                    //alert(res.err_code+res.err_desc+res.err_msg);
                    window.location.href="{:U('User/activity_join')}";
                }
        );
    }

</script>